package com.example.plant.activity

import android.content.DialogInterface
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProvider.NewInstanceFactory
import com.example.plant.databinding.ActivityLoginBinding
import com.example.plant.R
import com.example.plant.entity.LoginInfo








class LoginActivity : AppCompatActivity() {

    var loginInfo: LoginInfo = LoginInfo()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val loginBinding: ActivityLoginBinding = DataBindingUtil.setContentView(this, R.layout.activity_login)
        loginBinding.lifecycleOwner = this
        loginInfo = ViewModelProvider(this, NewInstanceFactory()).get(LoginInfo::class.java)
        loginBinding.userInfo = loginInfo
    }

    fun login(view: View)
    {
        val ACCOUNT ="123";
        val PASSWORD="123";
        if (loginInfo.account.get().equals(ACCOUNT)&&loginInfo.password.get().equals(PASSWORD))
        {
            var intent=Intent(this, MainActivity::class.java)
            startActivity(intent)
        }
        else
        {
            AlertDialog.Builder(this).setTitle("错误")
                .setMessage("用户名或密码错误")
                .setCancelable(false).setPositiveButton("确定",  DialogInterface.OnClickListener { dialog, which -> dialog.dismiss() }
                ).show();
        }

    }
}